import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  // {
  //   path: '/addprobation',
  //   name:'addprobation',
  //   component: () => import('@/views/components/addprobation'),
  //   hidden: true
  // },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '仪表盘', icon: 'yibiao', affix: true }
      }
    ]
  },
  {
    path: '/attestation',
    component: Layout,
    redirect: '/attestation/company',
    meta: { title: '认证管理', icon: 'renzheng' }, // roles权限控制，如admin账户登录才又权限看到'图书管理',editor登录看不到
    children: [
      {
        path: '/attestation/company',
        component: () => import('@/views/attestation/company'),
        name: 'company',
        meta: { title: '企业认证' },
        children: [
          {
            // path: '/attestation/company',
            // component: () => import('@/views/attestation/company'),
            // name: 'company',
            path: '/attestation/components/addprobation',
            name: 'addprobation',
            component: () => import('@/views//attestation/components/addprobation'),
            meta: { title: '企业认证' }

          }
        ]
      },
      {
        path: '/attestation/employee',
        component: () => import('@/views/attestation/employee'),
        name: 'employee',
        meta: { title: '员工名册管理' }
      },
      {
        path: '/attestation/company/addprobation',
        name: 'addprobation1',
        component: () => import('@/views/attestation/components/addprobation'),
        hidden: true
      },
      {
        path: '/attestation/company/startcertification',
        name: 'startcertification',
        component: () => import('@/views/attestation/components/startcertification'),
        hidden: true
      },
      {
        path: '/attestation/company/clientinformation',
        name: 'clientinformation',
        component: () => import('@/views/attestation/components/clientinformation'),
        hidden: true
      },
      {
        path: '/attestation/company/corporateaccount',
        name: 'corporateaccount',
        component: () => import('@/views/attestation/components/corporateaccount'),
        hidden: true
      },
      {
        path: '/attestation/company/authentication',
        name: 'authentication',
        component: () => import('@/views/attestation/components/authentication'),
        hidden: true
      },
      {
        path: '/attestation/employee/attestation/userinformation',
        name: 'userinformation',
        component: () => import('@/views/components/attestation/userinformation'),
        hidden: true
      }
    ]
  },
  {
    path: '/aggregation',
    component: Layout,
    redirect: '/aggregation/laborcontract',
    meta: { title: '聚合产品', icon: 'changpin', roles: ['admin'] }, // roles权限控制，如admin账户登录才又权限看到'图书管理',editor登录看不到
    children: [
      {
        path: '/aggregation/contract-guard',
        component: () => import('@/views/aggregation/contract-guard'),
        name: 'ContractGuard',
        meta: { title: '劳动合同卫士' }
      },
      {
        path: '/aggregation/laborcontract',
        name: 'laborcontract',
        component: () => import('@/views/aggregation/laborcontract'),
        meta: { title: '我的合同' },
        hidden: true
      },
      {
        path: '/aggregation/predefined-contract',
        name: 'PredefinedContract',
        component: () => import('@/views/aggregation/predefined-contract'),
        meta: { title: '合同范本' },
        hidden: true
      },
      {
        path: '/aggregation/pay',
        name: 'pay',
        component: () => import('@/views/aggregation/pay'),
        meta: { title: '支付页面' },
        hidden: true
      },
      {
        path: '/aggregation/employeemanual',
        component: () => import('@/views/aggregation/employeemanual'),
        name: 'employeemanual',
        meta: { title: '员工手册定制器' }
      },
      {
        path: '/aggregation/pneumaticcontrol',
        component: () => import('@/views/aggregation/pneumaticcontrol'),
        name: 'pneumaticcontrol',
        meta: { title: '入在离风控' }
      },
      {
        path: '/aggregation/positiondescription',
        component: () => import('@/views/aggregation/positiondescription'),
        name: 'positiondescription',
        meta: { title: '职位说明书词典' }
      },
      {
        path: '/aggregation/salarysheet',
        component: () => import('@/views/aggregation/salarysheet'),
        name: 'salarysheet',
        meta: { title: '电子工资条' }
      }
    ]
  },
  {
    path: '/aiinteraction',
    component: Layout,
    redirect: '/aiinteraction/contrast',
    meta: { title: 'AI交互工具', icon: 'AI' }, // roles权限控制，如admin账户登录才又权限看到'图书管理',editor登录看不到
    children: [
      {
        path: '/aiinteraction/contrast',
        component: () => import('@/views/aiinteraction/contrast'),
        name: 'contrast',
        meta: { title: '新旧版本对比' }
      },
      {
        path: '/aiinteraction/remotecontrol',
        component: () => import('@/views/aiinteraction/remotecontrol'),
        name: 'remotecontrol',
        meta: { title: '多人远程协作编辑' }
      },
      {
        path: '/aiinteraction/searching',
        component: () => import('@/views/aiinteraction/searching'),
        name: 'searching',
        meta: { title: '法条检索与比较' }
      },
      {
        path: '/aiinteraction/calculator',
        component: () => import('@/views/aiinteraction/calculator'),
        name: 'calculator',
        meta: { title: '劳动法计算器' }
      },
      {
        path: '/aiinteraction/signature',
        component: () => import('@/views/aiinteraction/signature'),
        name: 'signature',
        meta: { title: '电子签名' }
      }
    ]
  },
  {
    path: '/hrsystem',
    component: Layout,
    redirect: '/hrsystem/myhr',
    meta: { title: 'HR体系文件', icon: 'HRtixi' }, // roles权限控制，如admin账户登录才又权限看到'图书管理',editor登录看不到
    children: [
      {
        path: '/hrsystem/myhr',
        component: () => import('@/views/hrsystem/myhr'),
        name: 'myhr',
        meta: { title: '我的HR体系' }
      }
    ]
  },
  {
    path: '/professor',
    component: Layout,
    redirect: '/professor/myhr',
    meta: { title: '专家在线', icon: 'zhuanjia' }, // roles权限控制，如admin账户登录才又权限看到'图书管理',editor登录看不到
    children: [
      {
        path: '/professor/solicitor',
        component: () => import('@/views/professor/solicitor'),
        name: 'solicitor',
        meta: { title: '律师在线审查' }
      },
      {
        path: '/professor/flowpath',
        component: () => import('@/views/professor/flowpath'),
        name: 'flowpath',
        meta: { title: '民族流程实施' }
      },
      {
        path: '/professor/hr',
        component: () => import('@/views/professor/hr'),
        name: 'hr',
        meta: { title: 'HR专家在线辅导' }
      }
    ]
  },
  {
    path: '/explorer',
    component: Layout,
    redirect: '/explorer/hrideabank',
    meta: { title: '资源管理', icon: 'ziyuan' }, // roles权限控制，如admin账户登录才又权限看到'图书管理',editor登录看不到
    children: [
      {
        path: '/explorer/hrideabank',
        component: () => import('@/views/explorer/hrideabank'),
        name: 'hrideabank',
        meta: { title: 'HR智库10000' }
      },
      {
        path: '/explorer/labourlaw',
        component: () => import('@/views/explorer/labourlaw'),
        name: 'labourlaw',
        meta: { title: '劳动法库法典' }
      }
    ]
  },
  {
    path: '/counseling',
    component: Layout,
    redirect: '/counseling/normativedocuments',
    meta: { title: '咨询服务', icon: 'kefu' }, // roles权限控制，如admin账户登录才又权限看到'图书管理',editor登录看不到
    children: [
      {
        path: '/counseling/normativedocuments',
        component: () => import('@/views/counseling/normativedocuments'),
        name: 'normativedocuments',
        meta: { title: '人事规章风险评估' }
      },
      {
        path: '/counseling/stockassessment',
        component: () => import('@/views/counseling/stockassessment'),
        name: 'stockassessment',
        meta: { title: '人力资源风险评估' }
      }
    ]
  },
  {
    path: '/digitalarchives',
    component: Layout,
    redirect: '/digitalarchives/normativedocuments',
    meta: { title: '数字档案', icon: 'dangan' }, // roles权限控制，如admin账户登录才又权限看到'图书管理',editor登录看不到
    children: [
      {
        path: '/digitalarchives/staffrecord',
        component: () => import('@/views/digitalarchives/staffrecord'),
        name: 'staffrecord',
        meta: { title: '员工数字档案' }
      },
      {
        path: '/digitalarchives/testify',
        component: () => import('@/views/digitalarchives/testify'),
        name: 'testify',
        meta: { title: '出证存证' }
      }
    ]
  },
  {
    path: '/ordermanagement',
    component: Layout,
    redirect: '/ordermanagement/index',
    meta: { title: '订单管理', icon: 'dingdan' }, // roles权限控制，如admin账户登录才又权限看到'图书管理',editor登录看不到
    children: [
      {
        path: '/ordermanagement/index',
        component: () => import('@/views/ordermanagement/index'),
        name: 'ordermanagement',
        meta: { title: '订单管理' }
      }
    ]
  },
  {
    path: '/setmanagement',
    component: Layout,
    redirect: '/setmanagement/index',
    meta: { title: '设置管理', icon: 'shezhi' }, // roles权限控制，如admin账户登录才又权限看到'图书管理',editor登录看不到
    children: [
      {
        path: '/setmanagement/index',
        component: () => import('@/views/setmanagement/index'),
        name: 'setmanagement',
        meta: { title: '设置管理' }
      }
    ]
  }
]

export const asyncRoutes = [

  // {
  //   path: '/error',
  //   component: Layout,
  //   redirect: 'noRedirect',
  //   name: 'ErrorPages',
  //   meta: {
  //     title: 'Error Pages',
  //     icon: '404'
  //   },
  //   children: [
  //     {
  //       path: '401',
  //       component: () => import('@/views/error-page/401'),
  //       name: 'Page401',
  //       meta: { title: '401', noCache: true }
  //     },
  //     {
  //       path: '404',
  //       component: () => import('@/views/error-page/404'),
  //       name: 'Page404',
  //       meta: { title: '404', noCache: true }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

Router.selfaddRoutes = function(params) {
  Router.matcher = new Router().matcher
  Router.addRoutes(params)
}

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}
router.selfaddRoutes = function(params) {
  router.matcher = new Router().matcher
  router.addRoutes(params)
}

export default router
